<?php


namespace app\admin\controller;

class Up extends Common
{

    //编辑器上传图片
    public function upImage(){ //获取编辑器的上传信息
        $file = isset($_FILES['upload'])?$_FILES['upload']:'';
        if(!$file){
            return json(["uploaded"=>0,"error"=>["message"=>"请上传图片"]]);
        }
        $file = request()->file('upload');
        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->validate(['size'=>2097152,'ext'=>'jpg,png,gif'])->move( './uploads');
        if($info){
            return package(0,'上传成功',"/uploads/".$info->getSaveName());
        }else{
            // 上传失败获取错误信息
            return package(10016,$file->getError());
        }
    }
    public function upImage1(){ //获取编辑器的上传信息
        $file = isset($_FILES['upload'])?$_FILES['upload']:'';
        $callback = $_REQUEST['CKEditorFuncNum'];//获取回调ID
        if(!$file){
            return json(["uploaded"=>0,"error"=>["message"=>"请上传图片"]]);
        }
        $file = request()->file('upload');
        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->validate(['size'=>2097152,'ext'=>'jpg,png,gif'])->move( './uploads');
        if($info){

            $name =   str_replace('\\', '/', $info->getSaveName());

            echo  "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($callback,'"."/uploads/".$name."','');</script>";
//            return package(0,'success',$data);
        }else{
            // 上传失败获取错误信息
            return package(10016,$file->getError());
        }

    }
}